{ <description>

  Copyright (C) 2011 Anton A. Lindeberg lindeberg.a@gmail.com

  This source is free software; you can redistribute it and/or modify it under
  the terms of the GNU General Public License as published by the Free
  Software Foundation; either version 2 of the License, or (at your option)
  any later version.

  This code is distributed in the hope that it will be useful, but WITHOUT ANY
  WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
  details.

  A copy of the GNU General Public License is available on the World Wide Web
  at <http://www.gnu.org/copyleft/gpl.html>. You can also obtain it by writing
  to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
  MA 02111-1307, USA.
}
unit sslib;
interface
uses classes, SysUtils, Dialogs, Forms, db;
type
  TLanguage = (lgRus, lgUa, lgEng);
  TModeAEC = (mAdd, mEdit, mCopy, mList, mShow);
  TModeCreate = (mNew, mOpen);
  function Localize(const Caption: string): string;
  procedure LoadLocalize(const AFileName: string);
  procedure ScanDir(StartDir: string; Mask:string; List:TStrings);
  procedure SaveAsCSV(myFileName: string; myDataSet: TDataSet);
  function GetEnv(variable: string): string;

implementation

var LngList:TStringList = nil;


function Localize(const Caption: string): string;
begin
  Result:=LngList.Values[Caption];
  if Result='' then
  Result:=Caption;
end;

procedure LoadLocalize(const AFileName: string);
var
  S:string;
begin
  if not assigned(LngList) then  LngList:=TStringList.Create;
  S:=ExtractFileDir(ParamStr(0))+DirectorySeparator+'languages'+DirectorySeparator+AFileName;
  if FileExists(S) then
  begin
    LngList.Clear;
    LngList.LoadFromFile(s);
  end;
 end;

procedure ScanDir(StartDir: string; Mask: string; List: TStrings);
var
  SearchRec : TSearchRec;
begin
 if Mask = '' then Mask := '*.*';
 if StartDir[Length(StartDir)] <>  '\' then StartDir := StartDir + '\';
 if FindFirst(StartDir+Mask, faAnyFile, SearchRec) = 0 then
   begin
     repeat
      Application.ProcessMessages;
       if (SearchRec.Attr and faDirectory) <>  faDirectory then List.Add(SearchRec.Name)
        else
         if (SearchRec.Name <>  '..') and (SearchRec.Name <>  '.') then
           begin
//           List.Add(StartDir + SearchRec.Name + '\');
           ScanDir(StartDir + SearchRec.Name + '\',Mask,List);
           end;
     until FindNext(SearchRec) <>  0;
   FindClose(SearchRec);
   end;
end;

procedure SaveAsCSV(myFileName: string; myDataSet: TDataSet);
var
  myTextFile: TextFile;
  i: integer;
  s: string;
begin
  //create a new file
  AssignFile(myTextFile, myFileName);
  Rewrite(myTextFile);
   s := ''; //initialize empty string
   try
    //write field names (as column headers)
    for i := 0 to myDataSet.FieldCount - 1 do
      begin
        s := s + Format('"%s";', [myDataSet.Fields[i].FieldName]);
      end;
    Writeln(myTextFile, s);
     //write field values
    while not myDataSet.Eof do
      begin
        s := '';
        for i := 0 to myDataSet.FieldCount - 1 do
          begin
            s := s + Format('"%s";', [myDataSet.Fields[i].AsString]);
          end;
        Writeln(myTextfile, s);
        myDataSet.Next;
      end;
       finally
    CloseFile(myTextFile);
  end;
end;

function GetEnv(variable: string): string;
begin
  result:=GetEnvironmentVariable(variable);
end;



begin

end.
